package com.tanhua.server.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /*
     *  联系人添加
     *    请求方式和请求链接 : POST  /contacts
     *    请求参数: Body userId 好友的id
     *    返回值: 无
     * */

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        String str = map.get("userId").toString();
        Long usrId = Long.valueOf(str);
        messagesService.contacts(usrId);
        return ResponseEntity.ok(null);
    }

    /*
     *  联系人列表
     *    请求方式和请求链接 : GET  /contacts
     *    请求参数: Query page,pagesize
     *    返回值: PageResult   userInfoVo
     * */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "1") Integer pagesize) {


        PageResult request = messagesService.findFriends(page, pagesize);
        return ResponseEntity.ok(request);
    }

    /*
     *   根据环信id查询用户信息
     *    请求方式和请求链接 : GET /userInfo
     *    请求参数: huanxinId
     *    返回值: UserInfoVo
     * */

    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){

      UserInfoVo vo= messagesService.userInfo(huanxinId);
      return ResponseEntity.ok(vo);
    }


}
